<?php 

Class ModuleHotSearchKeywordResult extends CmsModule {
	private $dataHtml;
    public function __renderHead(){
		$filters = array('dateby', 'year', 'month', 'day', 'product','top');
		foreach($_GET as $k=>$v){
			if(in_array($k, $filters)){
				$$k = $v;
			}
		}
		$curr_datetime = date("Y-m-d H:i:s");
		$str_date=array();
		if ($year) {
			$str_date[] = $year;
		}
		if ($dateby !='month' && $month) {
			$str_date[] = $month;
		}
		if ($dateby == 'hour' && $day) {
			$str_date[] = $day;
		}
		$str_date = implode('-', $str_date);
		
		$str_product = AC::$member_product_list[$product];
		$str_top = AC::$member_top_list[$top];
		
		$html = '';
		if ($dateby == 'month') {
			$html = $this->getMonthHtml($year);
		}elseif ($dateby == 'date') {
			$html = $this->getDateHtml($year,$month);
		}elseif ($dateby == 'hour') {
			$html = $this->getDayHtml($year,$month, $day);
		}
		
		$dateby = ucwords( strtolower($dateby));
		$this->contents = <<<HTML
	<div id="result" class="hot_search_keyword_result">
		<div class="hd">
			<div class="utility">
				<a href="#" class="print">Print</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				Export to <a href="#">HTML</a>
			</div>
			<hr />
			<h1>Hot Search Keyword Report</h1>
			<div class="time">{$curr_datetime}</div><br />
			<div><b>By {$dateby}:</b> {$str_date}</div>
			<div><b>Product:</b> {$str_product}</div>
			<div><b>Top:</b> {$str_top}</div>
		</div>
		<div class="bd">
		<br />
<table width="100%">
{$html}
</table>
		</div>
	</div>
HTML;
    }
	private function getMonthHtml($year){
		$html = '<tr class="weight" bgcolor="#CCC"><td>排名</td><td>關鍵字</td><td>今日搜索</td><td>歷史總量搜索</td></tr>';
		for ($i =0; $i<12; $i++){
			$html .= '<tr><td>'.$i.'</td><td>Keyword'.$i.'</td><td>'.rand(100,9999).'</td><td>'.rand(1000,99999).'</td></tr>';
		}
		
		return $html;
	}
	private function getDateHtml($year,$month){
		$html = '<tr class="weight" bgcolor="#CCC"><td>排名</td><td>關鍵字</td><td>今日搜索</td><td>歷史總量搜索</td></tr>';
		for ($i =0; $i<31; $i++){
			$html .= '<tr><td>'.$i.'</td><td>Keyword'.$i.'</td><td>'.rand(100,9999).'</td><td>'.rand(1000,99999).'</td></tr>';
		}
		
		return $html;
	}
	private function getDayHtml($year,$month, $day){
		$html = '<tr class="weight" bgcolor="#CCC"><td>排名</td><td>關鍵字</td><td>今日搜索</td><td>歷史總量搜索</td></tr>';
		for ($i =0; $i<24; $i++){
			$html .= '<tr><td>'.$i.'</td><td>Keyword'.$i.'</td><td>'.rand(100,9999).'</td><td>'.rand(1000,99999).'</td></tr>';
		}
		
		return $html;
	}
}
?>